package br.mikhas.lab.scanner;

/**
 * Defines a transition from a state to another
 * 
 * @author Mikhail Domanoski
 * 
 */
public abstract class Transition implements Comparable<Transition> {

	/**
	 * The next state
	 */
	private final State state;

	/**
	 * Transition priority
	 */
	protected int priority = 0;

	/**
	 * Creates a new instance of the Transaction and defines it's next state
	 * 
	 * @param state
	 */
	public Transition(State state) {
		if (state == null)
			throw new NullPointerException("Next state must not be null");
		this.state = state;
	}

	/**
	 * Checks if this transition accepts the provided char
	 * 
	 * @param c
	 *            The char to check if the transition accepts
	 * @return <tt>true</tt> if the transition accepts the char
	 */
	abstract boolean accept(char c);

	/**
	 * Gets the next step
	 * 
	 * @return
	 */
	State getNextState() {
		return this.state;
	}

	@Override
	public int compareTo(Transition o) {
		int p = o.priority;
		if (priority > p)
			return 1;
		else if (priority < p)
			return -1;
		return 0;
	}

}
